package com.pxst.internalReports.controller;

import com.pxst.bank.service.SysBankCardFlowEntityService;
import com.pxst.internalReports.req.AddInternalTransferReq;
import com.pxst.internalReports.req.InternalTransferListReq;
import com.pxst.internalReports.resp.InternalTransferListResp;
import com.pxst.resp.ApiResp;
import com.pxst.resp.PageResp;
import com.pxst.tr.service.SysIntroversionOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * @author Txd
 * @since 2023-09-22 11:35:38
 */
@Api(tags = "内部转账相关接口")
@RestController
@RequestMapping("/internalTransfer")
@Validated
public class InternalTransferController {

    @Autowired
    private SysIntroversionOrderService sysIntroversionOrderService;

    @Autowired
    private SysBankCardFlowEntityService sysBankCardFlowEntityService;

    /**
     * 内部转账查询接口
     *
     * @param internalTransferListReq
     * @return ApiResp<PageResp < InternalTransferVo>>
     */
    @ApiOperation(value = "内部转账查询接口")
    @GetMapping("/internalTransferList")
    public ApiResp<PageResp<InternalTransferListResp>> getInternalTransfer(InternalTransferListReq internalTransferListReq) {
        return sysIntroversionOrderService.getInternalTransfer(internalTransferListReq);
    }

    /**
     * 内部转账-汇出报表接口
     *
     * @param internalTransferListReq description: 目前这个下载接口访问的时候会直接去进行下载数据的查询、
     *                                处理以及返回，并且返回的数据是不会被分页的条数所限制，会直接将所有符合条件的数据全部导出。
     * @author Chrissy
     */
    @ApiOperation(value = "内部转账下载接口")
    @GetMapping("/downloadInternalTransferList")
    public void downloadInternalTransfer(InternalTransferListReq internalTransferListReq, HttpServletResponse response) {
        sysIntroversionOrderService.downloadInternalTransfer(internalTransferListReq, response);
    }


    /**
     * 内部转账新增检查接口
     *
     * @param from          转账发起者
     * @param to            转账接受者
     * @param requestAmount 转账金额
     * @return description: 告诉前端检查的结果然后判断是否需要进行下一步的转账操作
     * @author Chrissy
     */
    @ApiOperation(value = "内部转账新增检查接口")
    @GetMapping("/checkLimit")
    public ApiResp checkLimit(Integer from, Integer to, BigDecimal requestAmount) {
        /**
         * 检查是否达到转账条件，达不到会向前端返回
         * tip:bc100会为每一张银行卡记录一条数据之后的每次
         */
        return sysBankCardFlowEntityService.checkLimit(from, to, requestAmount);
    }

    /**
     * 内部转账新增接口
     *
     * @param addInternalTransferReq
     * @return description: 返回通知信息
     * @author Chrissy
     */
    @ApiOperation(value = "内部转账新增接口")
    @GetMapping("/addInternalTransferList")
    public ApiResp addInternalTransferList(AddInternalTransferReq addInternalTransferReq) {
        return sysIntroversionOrderService.addInternalTransferList(addInternalTransferReq);
    }
}
